﻿using LabManagement.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.Security;

namespace OnlineLabManagement.Models
{
    public class LabRoleProvider:RoleProvider 
    {
        DataManager _databaseFactory;

        public DataManager DatabaseFactory
        {
            get
            {
                if (this._databaseFactory == null)
                {
                    string connection = WebConfigurationManager.AppSettings["DBConnectionString"].ToString();
                    this._databaseFactory = new DataManager(connection);
                }
                return this._databaseFactory;
            }
        }
        public override bool IsUserInRole(string username, string roleName)
        {
            return true;
        }

        public override string[] GetRolesForUser(string username)
        {
            if(this.DatabaseFactory.DataFactory.Users.Any(u=>u.UserName==username && u.IsAdmin==true)){
                return new string[] { "Admin" };
            }
            return new string[] { "OrgUser" };
        }

        // -- Snip --

        public override string[] GetAllRoles()
        {
            return new string[] { "OrgUser", "Admin" };
        }

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }
    }
}